<template>
  <div class="receipt-container">
    <div class="receipt">
      <div class="header">
        <div class="shop-name">瑶芳清颜全国祛痘连锁机构</div>
        <div class="shop-info">
          地址：忻府区杏林东街梧桐园店<br />
          电话：13935019456<br />
          营业时间：09:30-20:30
        </div>
      </div>

      <div class="divider"></div>

      <div class="customer-info">
        <div class="info-title">顾客消费凭证</div>
        <div class="info-row">
          <span class="info-label">顾客姓名：</span>
          <span>{{ customerInfo.name }}</span>
        </div>
        <div class="info-row">
          <span class="info-label">单据编号：</span>
          <span>{{ receiptInfo.receiptNo }}</span>
        </div>
        <div class="info-row">
          <span class="info-label">消费日期：</span>
          <span>{{ formatDateTime(receiptInfo.consumeTime) }}</span>
        </div>
        <div class="info-row">
          <span class="info-label">接待顾问：</span>
          <span>{{ receiptInfo.staffName }}</span>
        </div>
      </div>

      <div class="divider"></div>

      <table class="items-table">
        <thead>
          <tr>
            <th class="item-name">项目名称</th>
            <th class="item-qty">次数</th>
            <th class="item-price">金额</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item, index) in receiptInfo.items" :key="index">
            <td>{{ item.name }}</td>
            <td class="item-qty">{{ item.quantity }}</td>
            <td class="item-price">¥{{ item.price.toFixed(2) }}</td>
          </tr>
        </tbody>
      </table>

      <div class="divider"></div>

      <div class="info-row">
        <span class="info-label">项目合计：</span>
        <span>¥{{ receiptInfo.totalAmount.toFixed(2) }}</span>
      </div>
      <div class="info-row">
        <span class="info-label">优惠金额：</span>
        <span>-¥{{ receiptInfo.discountAmount.toFixed(2) }}</span>
      </div>
      <div class="total-row">
        <span>实付金额：</span>
        <span>¥{{ receiptInfo.paymentAmount.toFixed(2) }}</span>
      </div>

      <div class="info-row">
        <span class="info-label">支付方式：</span>
        <span>{{ receiptInfo.paymentMethod }}</span>
      </div>
      <div class="info-row">
        <span class="info-label">支付时间：</span>
        <span>{{ formatDateTime(receiptInfo.paymentTime) }}</span>
      </div>

      <div class="divider"></div>

      <div class="barcode">{{ receiptInfo.barcode }}</div>

      <div class="thank-you">感谢您的光临，期待再次为您服务！</div>

      <div class="footer">
        温馨提示：<br />
        1. 请妥善保管此小票，作为消费凭证<br />
        2. 产品使用后如有不适，请立即停止使用并咨询<br />
        3. 预约电话：13935019456<br />
        4. 本店保留最终解释权
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";

// 顾客信息
const customerInfo = ref({
  name: "林小美",
});

// 小票信息
const receiptInfo = ref({
  receiptNo: "REC20250511003",
  consumeTime: "2025-05-11T14:50:00",
  staffName: "欣欣",
  items: [{ name: "小部位脱毛", quantity: 1, price: 59.0 }],
  totalAmount: 59.0,
  discountAmount: 40.1,
  paymentAmount: 18.9,
  paymentMethod: "美团",
  paymentTime: "2025-05-11T14:50:00",
  barcode: "*REC20250511003*",
});

// 格式化日期时间
const formatDateTime = (dateString) => {
  const date = new Date(dateString);
  return date
    .toLocaleString("zh-CN", {
      year: "numeric",
      month: "2-digit",
      day: "2-digit",
      hour: "2-digit",
      minute: "2-digit",
      hour12: false,
    })
    .replace(/\//g, "-");
};
</script>

<style scoped>
.receipt-container {
  font-family: "Arial", sans-serif;
  max-width: 300px;
  margin: 0 auto;
  padding: 15px;
  background-color: white;
  color: #333;
}
.receipt {
  border: 1px dashed #ccc;
  padding: 15px;
}
.header {
  text-align: center;
  margin-bottom: 15px;
}
.shop-name {
  font-size: 22px;
  font-weight: bold;
  margin-bottom: 5px;
}
.shop-info {
  font-size: 12px;
  color: #666;
  line-height: 1.4;
}
.divider {
  border-top: 1px dashed #ccc;
  margin: 10px 0;
}
.customer-info {
  margin-bottom: 15px;
}
.info-title {
  font-weight: bold;
  margin-bottom: 5px;
  font-size: 14px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
  font-size: 13px;
}
.info-label {
  color: #666;
}
.items-table {
  width: 100%;
  border-collapse: collapse;
  margin: 15px 0;
  font-size: 13px;
}
.items-table th {
  text-align: left;
  padding: 5px 0;
  border-bottom: 1px dashed #ccc;
  font-weight: bold;
}
.items-table td {
  padding: 5px 0;
  border-bottom: 1px dashed #eee;
}
.items-table .item-name {
  width: 60%;
}
.items-table .item-price {
  text-align: right;
  width: 20%;
}
.items-table .item-qty {
  text-align: center;
  width: 20%;
}
.total-row {
  display: flex;
  justify-content: space-between;
  font-weight: bold;
  margin: 10px 0;
  padding-top: 5px;
  border-top: 1px dashed #ccc;
}
.footer {
  text-align: center;
  font-size: 12px;
  color: #666;
  margin-top: 15px;
  line-height: 1.5;
}
.barcode {
  text-align: center;
  margin: 10px 0;
  font-family: "Libre Barcode 128", cursive;
  font-size: 30px;
}
.thank-you {
  text-align: center;
  font-style: italic;
  margin: 10px 0;
}
</style>
